﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataModel;
using SchoolBusiness;

namespace SchoolAdministration
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        private readonly Student blstd = new Student();
        private readonly BLRoutine _blroutine = new BLRoutine();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DDLSection.Enabled = false;
                LoadClass();

            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }
        public void LoadClass()
        {
            List<Grade> grade = _blroutine.GetGrade();
            DDLClass.Items.Clear();
            DDLClass.Items.Insert(0, new ListItem("Class", "0"));
            DDLClass.DataSource = grade;
            DDLClass.DataTextField = "ClassName";
            DDLClass.DataValueField = "ClassId";
            DDLClass.DataBind();

        }
        public void LoadSection(int grade)
        {
            List<MStudent> section = _blroutine.GetSection(grade);
            DDLSection.Items.Clear();
            DDLSection.Items.Insert(0, new ListItem("Section", "0"));
            DDLSection.DataSource = section;
            DDLSection.DataTextField = "Section";
            DDLSection.DataValueField = "Section";
            DDLSection.DataBind();

        }
        public void LoadSubject(int classid)
        {
            List<Subject> lsub = new List<Subject>();
            lsub = _blroutine.GetSubjectByClassId(classid);
            DDLSubject.Items.Clear();
            DDLSubject.Items.Insert(0, new ListItem("--Subject--", "0"));
            DDLSubject.DataSource = lsub;
            DDLSubject.DataTextField = "SubjectName";
            DDLSubject.DataValueField = "SubjectId";
            DDLSubject.DataBind();
        }
        protected void DDLClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            DDLSection.Enabled = true;
            //DDLSubject.Enabled = false;
           // GridViewStudentList.Visible = false;
            int grade = Int32.Parse(DDLClass.SelectedItem.Value);
            LoadSection(grade);
        }
        protected void DDLSection_SelectedIndexChanged(object sender, EventArgs e)
        {
           // DDLSubject.Enabled = true;
           // GridViewStudentList.Visible = false;
            int classid = Int32.Parse(DDLClass.SelectedItem.Value);
            LoadSubject(classid);

        }
    }
}